const app = getApp();

Page({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    currentGuard: app.globalData.currentGuard,
  },
  onLoad() {
    const pages = getCurrentPages();
    const currentPage = pages[pages.length - 1];
    const options = currentPage.options;
    if (options.referrer === 'friend') {
      wx.redirectTo({
        url: '../index/index'
      })
    }
  },
  onShow() {
  },
  onShareButtonTap() {
    console.log('onShareButtonTap')
    wx.shareAppMessage({
      title: '马上召唤你的守护神，让你寄托良愿，安抚心灵，功德+1',
      imageUrl: 'https://6475-dunhuang-2guh623s2047d720-1318886299.tcb.qcloud.la/share-image.png',
      path: '/pages/index/index',
      success: function(res) {
        // 分享成功
      },
      fail: function(res) {
        // 分享失败
      }
    });
  },
  onShareTimeline() {
    return {
      title: '马上召唤你的守护神，让你寄托良愿，安抚心灵，功德+1',
      imageUrl: 'https://6475-dunhuang-2guh623s2047d720-1318886299.tcb.qcloud.la/share-image.png',
      path: '/pages/index/index',
      query: 'referrer=friend'
    }
  },
  onShareAppMessage() {
    return {
      title: '马上召唤你的守护神，让你寄托良愿，安抚心灵，功德+1',
      imageUrl: 'https://6475-dunhuang-2guh623s2047d720-1318886299.tcb.qcloud.la/share-image.png',
      query: 'referrer=friend',
      path: '/pages/index/index'
    }
  },
  onLaunch (options) {
    console.log(options)
    // Do something initial when launch.
  },
  remindHandler() {
    wx.navigateTo({
      url: `../remind/index`
    })
  },
  longPressHandler() {
    var imgUrl = 'https://6475-dunhuang-2guh623s2047d720-1318886299.tcb.qcloud.la/community-code.png?sign=7e22212d20bfbf78cf40317026b8278c&t=1687671929';
    wx.previewImage({
      current: imgUrl,
      urls: [imgUrl],
      success: function() {
        wx.scanCode({
          success: function(res) {
            // 二维码识别成功，获取到结果
            var result = res.result;
            console.log(result);
            // 进行相应的处理
          },
          fail: function(res) {
            // 二维码识别失败或取消
            console.log(res);
          }
        });
      },
      fail: function(res) {
        // 预览图片失败
        console.log(res);
      }
    });
  },
  /**
   * 组件的方法列表
   */
  methods: {
  }
})
